<?php

include_once 'BaseDAO.php';
//include_once '../util/plog/classes/plog.php';


class ProductDAO extends BaseDAO {
	
	public function __construct() {
		parent::__construct ();
	
		//		$this->log = Plog::factory(__FILE__);			
	}
	
	public function queryAllBySubType($type, $orderByField, $asc) {
		
//		$sql = "select 
//				p.p_id,prod_no,p_name,add_date,sort,
//				sb_id,price,sell_price,sell_mode,
//				pre_year,pre_month,pre_day,ship_month,
//				ship_day,title,pic,prod_txt,pa_id,
//				count,attr,rank		
//				from product p join prod_attr pa on p.p_id=pa.p_id 
//				where sort=$type order by $orderByField $asc";
		$sql = "select 
				p.p_id,prod_no,p_name,add_date,sort,
				sb_id,price,sell_price,sell_mode,
				pre_year,pre_month,pre_day,ship_month,
				ship_day,title,pic,prod_txt,
				rank		
				from product p 
				where sort=$type order by $orderByField $asc";
//		echo  $sql;
		$result = @mysql_query ( $sql );
		return $this->toArray ( $result );
	}
	public function queryProd_attrByPaId($pa_id) {
		
		$sql = "select p.p_id,prod_no,p_name,add_date,sort,
				p.sb_id,price,sell_price,sell_mode,
				pre_year,pre_month,pre_day,ship_month,
				ship_day,title,p.pic,prod_txt,pa.pa_id,
				count,attr,rank ,sb.cm_id,sb.logo_name,
				sb.logo_name_en,sb.addr,sb.tel
				from product p join prod_attr pa on p.p_id=pa.p_id and  pa_id=$pa_id
			join supplier_brand sb on p.sb_id=sb.sb_id
		";
		
		$sql = "select p.p_id,prod_no,p_name,add_date,sort,
				p.sb_id,price,sell_price,sell_mode,
				pre_year,pre_month,pre_day,ship_month,
				ship_day,title,p.pic,prod_txt,
				rank ,sb.cm_id,sb.logo_name,
				sb.logo_name_en,sb.addr,sb.tel
				from product p join supplier_brand sb on p.sb_id=sb.sb_id
				where p_id=$pa_id 	";
//		echo  $sql;
		$result = @mysql_query ( $sql );
		return $this->toArray ( $result );
	}
	
	public function queryPopProudction($type) {
//		$sql = "select 
//				p.p_id,prod_no,p_name,add_date,sort,
//				sb_id,price,sell_price,sell_mode,
//				pre_year,pre_month,pre_day,ship_month,
//				ship_day,title,pic,prod_txt,pa_id,
//				count,attr,rank		
//				from product p join prod_attr pa on p.p_id=pa.p_id 
//			    where sort=$type order by rank desc limit 5";
		$sql = "select 
				p.p_id,prod_no,p_name,add_date,sort,
				sb_id,price,sell_price,sell_mode,
				pre_year,pre_month,pre_day,ship_month,
				ship_day,title,pic,prod_txt,
				rank		
				from product p 
				where sort=$type order by rank desc limit 5";
//		echo $sql;
		$result = @mysql_query ( $sql );
		return $this->toArray ( $result );
	}
		public function querySpecialPriceProudction($type) {
		$sql = "select 
				p.p_id,prod_no,p_name,add_date,sort,
				sb_id,price,sell_price,sell_mode,
				pre_year,pre_month,pre_day,ship_month,
				ship_day,title,pic,prod_txt,pa_id,
				count,attr,rank		
				from product p left join prod_attr pa on p.p_id=pa.p_id 
			    where 2=2 and p.pic is not null order by add_date desc limit 3";
		//echo $sql;
		$result = @mysql_query ( $sql );
		return $this->toArray ( $result );
	}
	
	public function queryNewestSupplierProduct($sb_id){
		$sql = " select * from product where pic is not null and sb_id=$sb_id";
		$result = @mysql_query ( $sql );
		return $this->toArray ( $result );
	}
	
	public function queryHappyPrice() {
		$sql = "select p.* from product p where 2=2 and p.pic is not null order by add_date desc limit 10";
		//echo $sql;
		$result = @mysql_query ( $sql );
		return $this->toArray ( $result );
	}
	
	public function queryProductList($orderBy) {
		$sql = "select p.*, sb.logo_name from product p join supplier_brand sb on p.sb_id=sb.sb_id where 2=2 and p.pic is not null order by $orderBy";
		//echo $sql;
		$result = @mysql_query ( $sql );
		return $this->toArray ( $result );
	}
}
?>